﻿namespace WordCloudClient.ViewModels
{
    public class ViewSystemSettingViewModel : DataGridCommonVM
    {
        public ViewSystemSettingViewModel(SystemService systemService, WinEditHelper winEditHelper) : base(systemService, winEditHelper)
        {
            EditWinAddress = "WinEditDictionary";
        }
        public override void BindData()
        {
            List<DictionaryEntity> listEntity = _systemService.GetDictionaryEntities(QueryModel, ref TotalPages, ref TotalCount);
            ObjectEntities = new ObservableCollection<object>(listEntity);
            PaginationModel = ControlHelper.GetPaginationModel(QueryModel.PageIndex, QueryModel.PageSize, TotalPages, TotalCount);
        }

        public override void ExecuteDelete()
        {
            DictionaryEntity DictionaryEntity = (DictionaryEntity)SelectObject;
            if (string.IsNullOrEmpty(DictionaryEntity.Name))
            {
                MessageTips.InfoMessage("请选择一条数据");
                return;
            }
            if (MessageTips.AccentMessage($"是否删除{DictionaryEntity.Name}？") == MessageBoxResult.Yes)
            {
                if (_systemService.DeleteDictionary(DictionaryEntity))
                {
                    MessageTips.SuccessMessage("删除成功！");
                    BindData();
                }
            }
        }
    }
}
